{* $Id$ *}
{include_core file="admin/lib/header.html" title="用户展示"}
<div class="page-header border-bottom clearfix">
    <h2 class="left">用户管理<span>编辑用户</span></h2>
    <a href="{AnUrl('user/admin')}?{base64_decode($query_string)}" class="btn btn-default btn-sm right">&lt;&nbsp;返回用户列表</a>
</div>
<!--start:用户新增-->
<div class="add-form">
    <form class="js_creatForm" action="{AnUrl('user/admin/update')}?{$query_string}" method="post" enctype="multipart/form-data">
        <input type="hidden" name="info[id]" value="{$user_info.id}">
        <input type="hidden" name="dealer_address_id" value="{$dealer_address_id}">
        <input type="hidden" name="query_string" value="{$query_string}">
        <table class="table" cellpadding="0" cellspacing="0">
            {if $role_id == user_config::AGENCY}
            <tr class="js_agency_level">
                <th><label class="add-f-label">合伙人等级：</label></th>
                <td>
                    <label><input type="radio" name="info[dealer_level]" value="1"{if $user_info.parent_id==0} checked="checked"{/if}>&nbsp;1级&nbsp;</label>&nbsp;&nbsp;
                    <label><input type="radio" name="info[dealer_level]" value="2"{if $user_info.parent_id>0} checked="checked"{/if}>&nbsp;2级&nbsp;</label>
                </td>
            </tr>
            <tr class="js_parent_agency"{if $user_info.parent_id == 0} style="display:none"{/if}>
            <th><label class="add-f-label">父级合伙人：</label></th>
            <td>
                {if !isset($PARENT_AGENCY_LIST)}
                {$PARENT_AGENCY_LIST = user_helper::get_dealers_level_info(1)}
                {/if}
                <select placeholder="请选择父级合伙人" class="add-f-ipt1" id="suggest_parent_agency" name="info[parent_id]">
                    <option value="0"{if $user_info.parent_id == 0} selected="selected"{/if}>请选择父级合伙人</option>
                    {foreach $PARENT_AGENCY_LIST as $k => $v}
                    <option value="{$v.id}"{if $v.id == $user_info.parent_id} selected="selected"{/if}>{$v.realname}({$v.mobile})</option>
                    {/foreach}
                </select>
            </td>
            </tr>
            <tr class="js_aboutDealer" style="display:none;">
                <th><label class="add-f-label">合伙人属性：</label></th>
                <td>
                    <label><input type="radio" name="is_old" value="1"{if isset($is_old) && $is_old == 1} checked{/if}>&nbsp;老合伙人</label>&nbsp;&nbsp;
                    <label><input type="radio" name="is_old" value="0"{if isset($is_old) && $is_old == 0} checked{/if}>&nbsp;新合伙人</label>
                </td>
            </tr>
            {/if}
            <tr>
                <th><label class="add-f-label">用户名：</label></th>
                <td>
                    <input name="info[user_name]" style="width:490px;" class="add-f-ipt1 js_userName" value="{$user_info.user_name}">
                    <!--{$user_info.user_name}-->
                </td>
            </tr>
            {*
            <tr>
                <th><label class="add-f-label">昵称：</label></th>
                <td>
                    <input name="info[nickname]" style="width:490px;" type="text" class="add-f-ipt1" value="{$user_info.nickname}">
                    <div class="tips"><span style="line-height: 34px;color: #f00;margin-right: 10px;">*</span>请输入昵称</div>
                </td>
            </tr>
            *}
            <tr>
                <th><label class="add-f-label">手机号码：</label></th>
                <td>
                    <input name="info[mobile]" style="width:490px;" type="text" class="add-f-ipt1 js_mobile" value="{$user_info.mobile}">
                    <div class="tips">输入手机号码</div>
                </td>
            </tr>
            <tr>
                <th><label class="add-f-label">密码：</label></th>
                <td>
                    <input name="info[password]" style="width:490px;" type="text" class="add-f-ipt1">
                    <div class="tips">如不修改，则不用填写</div>
                </td>
            </tr>
            <tr>
                <th><label class="add-f-label">真实姓名：</label></th>
                <td>
                    <input name="info[realname]" style="width:490px;" type="text" class="add-f-ipt1" value="{$user_info.realname}">
                    <div class="tips">请输入真实姓名</div>
                </td>
            </tr>
            <tr>
                <th><label class="add-f-label">邮箱地址：</label></th>
                <td>
                    <input name="info[email]" style="width:490px;" type="text" class="add-f-ipt1 js_email" value="{$user_info.email}">
                    <div class="tips">输入邮箱地址</div>
                </td>
            </tr>
            <tr class="js_aboutDealer" style="display:none">
                <th><label class="add-f-label">微信号：</label></th>
                <td>
                    <input name="info[weixin]" style="width:490px;" type="text" value="{$user_info.weixin}" class="add-f-ipt1 js_email">
                    <div class="tips"><span style="line-height: 34px;color: #f00;margin-right: 10px;">*</span>输入微信号码</div>
                </td>
            </tr>
            <tr class="js_aboutDealer" style="display:none">
                <th><label class="add-f-label">银行名称：</label></th>
                <td>
                    <input name="info[bank_name]" style="width:490px;" type="text" value="{$user_info.bank_name}" class="add-f-ipt1 js_email">
                    <div class="tips"><span style="line-height: 34px;color: #f00;margin-right: 10px;">*</span>输入银行名称</div>
                </td>
            </tr>
            <tr class="js_aboutDealer" style="display:none">
                <th><label class="add-f-label">开户行：</label></th>
                <td>
                    <input name="info[account_bank]" style="width:490px;" type="text" value="{$user_info.account_bank}" class="add-f-ipt1 " max-length="100">
                    <div class="tips">输入开户行名称</div>
                </td>
            </tr>
            <tr class="js_aboutDealer" style="display:none">
                <th><label class="add-f-label">身份证号码：</label></th>
                <td>
                    <input name="info[id_card_no]" style="width:490px;" type="text" value="{$user_info.id_card_no}" class="add-f-ipt1 " max-length="100">
                    <div class="tips">输入身份证号码</div>
                </td>
            </tr>
            <tr class="js_aboutDealer" style="display:none">
                <th><label class="add-f-label">家庭住址：</label></th>
                <td>
                    <input name="info[address]" style="width:490px;" type="text" value="{$user_info.address}" class="add-f-ipt1 " max-length="100">
                    <div class="tips">输入家庭住址</div>
                </td>
            </tr>
            <tr class="js_aboutDealer" style="display:none">
                <th><label class="add-f-label">银行卡号：</label></th>
                <td>
                    <input name="info[bank_code]" style="width:490px;" type="text" value="{$user_info.bank_code}" class="add-f-ipt1 js_email">
                    <div class="tips"><span style="line-height: 34px;color: #f00;margin-right: 10px;">*</span>输入银行卡号</div>
                </td>
            </tr>
            <tr class="js_aboutDealer" style="display:none">
                <th><label class="add-f-label">是否打开抱抱币:</label></th>
                <td>
                    {if $user_info && $user_info.is_bbcoin_enable == 0}
                    <label><input class="js_open" name="info[is_bbcoin_enable]" type="radio" value="1"{if $user_info.is_bbcoin_enable == 1} checked{/if} > 打开</label>&nbsp;&nbsp;
                    <label><input class="js_close" name="info[is_bbcoin_enable]" type="radio" value="0"{if $user_info.is_bbcoin_enable == 0} checked{/if} > 关闭</label>
                    {else}
                    &nbsp;&nbsp;已打开
                    {/if}
                </td>
            </tr>
            <tr class="js_aboutDealer" style="display:none">
                <th valign="top"><label class="add-f-label">上传身份证正面照：</label></th>
                <td class="perUpOuter">
                    <div class="clearfix">
                        <div class="btn-upload left">
                            <a href="javascript:void(0);"><i class="icon-upload"></i>上传正面照</a>
                            <input type="file" class="js_upFile" name="cert_idcard_front">
                        </div>
                        <span class="tips left">&nbsp;&nbsp;&nbsp;图片比例：528*333</span>
                    </div>
                    <div class="js_upFileBox">
                        <div class="js_upFileBox">
                            {if $user_store_info.cert_idcard_front}
                            <img src="{aliysso_helper::_image($user_store_info.cert_idcard_front, 'small')}" width="270">
                            {else}
                            <!-- <img src="{$smarty.const.SITE_URL}/images/m/default/focus_default.jpg" width="270"> -->
                            {/if}
                        </div>
                    </div>
                </td>
            </tr>
            <tr class="js_aboutDealer" style="display:none">
                <th valign="top"><label class="add-f-label">上传身份证背面照：</label></th>
                <td class="perUpOuter">
                    <div class="clearfix">
                        <div class="btn-upload left">
                            <a href="javascript:void(0);"><i class="icon-upload"></i>上传背面照</a>
                            <input type="file" class="js_upFile" name="cert_idcard_back">
                        </div>
                        <span class="tips left">&nbsp;&nbsp;&nbsp;图片比例：528*333</span>
                    </div>
                    <div class="js_upFileBox">
                        <div class="js_upFileBox">
                            {if $user_store_info.cert_idcard_back}
                            <img src="{aliysso_helper::_image($user_store_info.cert_idcard_back, 'small')}" width="270">
                            {else}
                            <!-- <img src="{$smarty.const.SITE_URL}/images/m/default/focus_default.jpg" width="270"> -->
                            {/if}
                        </div>
                    </div>
                </td>
            </tr>
            <tr class="js_aboutDealer" style="display:none">
                <th valign="top"><label class="add-f-label">上传合同照：</label></th>
                <td class="perUpOuter">
                    <div class="clearfix">
                        <div class="btn-upload left">
                            <a href="javascript:void(0);"><i class="icon-upload"></i>上传合同照</a>
                            <input type="file" class="js_upFile" name="cert_company">
                        </div>
                        <span class="tips left">&nbsp;&nbsp;&nbsp;图片比例：1107*690</span>
                    </div>
                    <div class="js_upFileBox">
                        <div class="js_upFileBox">
                            {if $user_store_info.cert_company}
                            <img src="{aliysso_helper::_image($user_store_info.cert_company, 'small')}" width="270">
                            {else}
                            <!-- <img src="{$smarty.const.SITE_URL}/images/m/default/focus_default.jpg" width="270"> -->
                            {/if}
                        </div>
                    </div>
                </td>
            </tr>
            <tr class="js_aboutDealer" style="display:none">
                <th><label class="add-f-label">允许开票：</label></th>
                <td>
                    <label><input type="radio" value="1" name="info[is_invoice]"{if $user_info.is_invoice == 1}checked="checked"{/if} />允许</label> &nbsp;&nbsp;
                    <label><input type="radio" value="0" name="info[is_invoice]"{if $user_info.is_invoice == 0}checked="checked"{/if} />不允许</label>
                </td>
            </tr>
            {*
            {if $user_info.parent_id > 0}
            <tr class="js_aboutDealer" style="display:none">
                <th><label class="add-f-label">返还差价：</label></th>
                <td>
                    <label><input type="radio" value="1" name="info[is_return_diff]"{if $user_info.is_return_diff == 1}checked="checked"{/if} />允许</label> &nbsp;&nbsp;
                    <label><input type="radio" value="0" name="info[is_return_diff]"{if $user_info.is_return_diff == 0}checked="checked"{/if} />不允许</label>
                </td>
            </tr>
            {/if}
            *}
            <tr>
                <th><label class="add-f-label">用户状态：</label></th>
                <td>
                    <label><input type="radio" value="1" name="info[status]"{if $user_info.status == 1}checked="checked"{/if} />正常</label> &nbsp;&nbsp;
                    <label><input type="radio" value="0" name="info[status]"{if $user_info.status == 0}checked="checked"{/if} />已锁定</label>
                </td>
            </tr>
            <tr>
                <th>&nbsp;</th>
                <td class="noborder">
                    <button type="submit" class="btn btn-success js_submit">&nbsp;&nbsp;&nbsp;确认&nbsp;&nbsp;&nbsp;</button>
                </td>
            </tr>
        </table>
    </form>
</div>
<!--end:用户新增-->
<script>
    var isAllowBBcoinOpen = false;
    $(function () {
        // 初始化用户编辑页面
        if ("{$user_info.dealer_level}" > 0) {
            $('.js_aboutDealer').slideDown();
            // 设置默认助理
            $('select[name="info[assistant]"]').val('{$user_info.assistant}');
        } else {
            $('.js_aboutDealer').slideUp();
        }

        /*   //初始化省份列表
         $.ajax({
         url : 'area/admin/ajax_get_provinces',
         type : 'get',
         dataType : 'json',
         success : function(province_list){
         for (var i in province_list) {

         var opt = $('<option value="'+province_list[i]['area_code']+'">'+province_list[i]['area']+'</option>');
         $('.js_provinceList').append(opt);
         }

         {if $area['province_info']}
         $('select[name="province"]').val("{$area.province_info.area_code}");

         $('.js_provinceList').change();

         {/if}

         {if $area['city_info']}
         $('.js_provinceList').val("{$area.province_info.area_code}");

         $('.js_cityList').val("{$area.city_info.area_code}");
         $('.js_cityList').change();
         $('.js_countyList').val("{$area['county_info']['area_code']}");
         {/if}
         }
         });

         $('.js_provinceList').change(function(){
         //获取值
         if($(this).val() ! == '000000'){
         var province = $(this).val();
         $('.js_cityList').fadeIn();
         $('.js_countyList').fadeOut();
         $('.js_countyList').val('000000');
         }else{
         $('.js_cityList').fadeOut();
         $('.js_cityList').val('000000');
         $('.js_countyList').fadeOut();
         $('.js_countyList').val('000000');

         return false;
         }
         $('.js_cityList').empty();
         $('.js_cityList').append('<option value="000000">请选择城市</option>');
         $('.js_countyList').empty();
         $('.js_countyList').append('<option value="000000">请选择区(县)</option>');

         //发送ajax
         $.ajax({
         url : 'area/admin/ajax_get_citys?province_code='+province,
         success : function(city_list){
         for (var i in city_list) {
         var opt = $('<option value="'+city_list[i]['area_code']+'">'+city_list[i]['area']+'</option>');
         $('.js_cityList').append(opt);
         }

         {if $area.city_info}
         $('.js_cityList').val("{$area.city_info.area_code}");
         {/if}
         },
         type : 'get',
         dataType : 'json',
         async : false,
         });


         });
         //城市
         $('.js_cityList').change(function(){
         if ( $('.js_provinceList').val() = == '000000' || $('.js_cityList').val() = == '000000') {
         $('.js_countyList').fadeOut();
         $('.js_countyList').val('000000');
         return false;
         } else {
         $('.js_countyList').fadeIn();
         }

         $('.js_countyList').empty();
         $('.js_countyList').append('<option value="000000">请选择区(县)</option>');

         //获取省份的key和值
         var province_code = $('.js_provinceList').val();
         var pro_text = $('.js_provinceList').text();

         //获取城市的值
         var city_code = $(this).val();

         //发送ajax
         $.ajax({
         url : 'area/admin/ajax_get_countys?province_code='+province_code+'&city_code='+city_code,
         type : 'get',
         dataType : 'json',
         success : function(county_list){
         for (var i in county_list) {
         var opt = $('<option value="'+county_list[i]['area_code']+'">'+county_list[i]['area']+'</option>');
         $('.js_countyList').append(opt);
         }

         {if $area['county_info']}
         $('.js_countyList').fadeIn();
         $('.js_countyList').val("{$area['county_info']['area_code']}");
         {/if}
         }
         });

         }); */


        // 提交验证
        $('.js_submit').click(function (e) {
            e.preventDefault();
            var password = $.trim($('input[name="info[password]"]').val());
            var email = $.trim($('.js_email').val());
//    var nickname         = $.trim($('input[name="info[nickname]"]').val());
            var mobile = $.trim($('.js_mobile').val());
            var weixin = $.trim($('input[name="info[weixin]"]').val());
            var bank_name = $.trim($('input[name="info[bank_name]"]').val());
            var bank_code = $.trim($('input[name="info[bank_code]"]').val());
            var store_house = $.trim($('input[name="info[store_house]"]').val());
            var province = $('.js_provinceList').val();
            var level = $('.js_agency_level').find(':checked').val();

            if (password) {
                if (is_pwd_null(password)) {
                    showMsg('密码内不能存在空字符');
                    return;
                }
                if (getStringLen(password) < 6) {
                    showMsg('密码不能少于6个字符');
                    return;
                }

            }

            if (mobile) {
                if (!checkStr(mobile, 'mobile')) {
                    showMsg('手机号码格式不正确');
                    return;
                }
            }

            if ("{user_config::AGENCY}" == "{$role_id}") {

                if (!weixin) {
                    showMsg('微信号不能为空!');
                    return false;
                }
                if (!mobile) {
                    showMsg('手机号不能为空!');
                    return false;
                }
                if (!bank_name) {
                    showMsg('银行名称不能为空!');
                    return false;
                }
                if (!bank_code) {
                    showMsg('银行卡号不能为空!');
                    return false;
                }
                {if $user_info.is_bbcoin_enable != 1}
                if ($('input.js_open').attr('checked')) {
                    $('.js_confirmBBcoinOpenDiv').css('display', '');
                    $('.float-bg').css('display', '');
                    return false;
                    if (isAllowBBcoinOpen) {
                        return true;
                    } else {
                        return false;
                    }
                }


                {/if}
            }

            if (level != null) {
                var parent_agency_id = $('#suggest_parent_agency').val();
                if (level == 2 && parent_agency_id == 0) {
                    showMsg('请指定父级合伙人!');
                    return false;
                }
            }

            $('.js_creatForm').submit();
        });

//上传图片预览
        $(".js_upFile").each(function (i) {
            $(this).change(function (e) {
                handleFileSelect($(this), 270);
            });
        });

        $('#js_btnAllowBBcoinOpen').click(function () {
            isAllowBBcoinOpen = true;
            $('.js_creatForm').submit();
        });

        $('#js_btnCancelBBcoinOpen').click(function () {
            $('.js_confirmBBcoinOpenDiv').css('display', 'none');
            $('.float-bg').css('display', 'none');
            $('.js_close').attr('checked', 1);
            // $('.js_open').attr('checked', false);
            // $('input[name="info[is_bbcoin_enable]"]').val(0);
            isAllowBBcoinOpen = false;
        });

    });

    //if ("{$user_info['dealer_level']}" > 0) {
    //    $('.js_parentDealerList').slideDown('fast');
    //    $('selected[name="info[parent_id]"]').val("{$user_info.parent_id}");
    //    $('selected[name="info[parent_id]"]').find('option[value="{$user_info.parent_id}"]').attr('selected', 'selected');
    //}

    $('.js_agency_level').on('click', 'input[type="radio"]', function () {
        var level = $(this).val();
        if (level == 1) {
            $('.js_parent_agency').hide();
        } else if (level == 2) {
            $('.js_parent_agency').show();
        }
    })

</script>
<div class="float-confirm js_confirmBBcoinOpenDiv" style="top: 45%; z-index: 20000; left: 45%; position:fixed;margin-left: 0px; margin-top: 0px; display:none">
    <div class="float-confirm-con">
        <p>确定要打开抱抱币吗?</p>
        <div class="float-confirm-btns">
            <a class="btn btn-success btn-sm" id="js_btnAllowBBcoinOpen" href="javascript:void(0);">确定</a>
            <a class="btn btn-default btn-sm" id="js_btnCancelBBcoinOpen" href="javascript:void(0);">取消</a>
        </div>
    </div>
</div>
<div class="float-bg" style="z-index: 19999;display:none;"></div>

{include_core file="module/suggestion.html" id="suggest_parent_agency"}
{include_core file="admin/lib/footer.html"}